Public Class Cliente

    Public Shared Function esNavegadorMovil() As Boolean
        Dim contexto As Web.HttpContext = Web.HttpContext.Current
        Dim respuesta As Boolean = False

        'Porbar con la validacion interna de .NET
        If contexto.Request.Browser.IsMobileDevice Then
            respuesta = True
        End If

        'Chequear el header HTTP_X_WAP_PROFILE
        If contexto.Request.ServerVariables("HTTP_X_WAP_PROFILE") Is Nothing = False Then
            respuesta = True
        End If

        'Chequear el header HTTP_ACCEPT
        If contexto.Request.ServerVariables("HTTP_ACCEPT") Is Nothing = False And contexto.Request.ServerVariables("HTTP_ACCEPT").ToLower().Contains("wap") Then
            respuesta = True
        End If

        'Chequear el header HTTP_USER_AGENT
        If contexto.Request.ServerVariables("HTTP_USER_AGENT") Is Nothing = False Then
            Dim arrayPalabras() As String
            Dim i As Integer
            arrayPalabras = "midp,j2me,avant,docomo,novarra,palmos,palmsource,240x320,opwv,chtml,pda,windowsce,mmp/,blackberry,mib/,symbian,wireless,nokia,hand,mobi,phone,cdm,up.b,audio,SIE-,SEC-,samsung,HTC,mot-,mitsu,sagem,sony,alcatel,lg,eric,vx,NEC,philips,mmm,xx,panasonic,sharp,wap,sch,rover,pocket,benq,java,pt,pg,vox,amoi,bird,compal,kg,voda,sany,kdd,dbt,sendo,sgh,gradi,jb,dddi,moto,iphone,psp".Split(",")
            For i = 0 To arrayPalabras.Length - 1
                If contexto.Request.ServerVariables("HTTP_USER_AGENT").ToLower().Contains(arrayPalabras(i).ToLower) Then
                    'chequeo extra por el Officeliveconector
                    If contexto.Request.ServerVariables("HTTP_USER_AGENT").ToLower().Contains("officeliveconnector") Then
                        respuesta = False
                        Exit For
                    Else
                        respuesta = True
                        Exit For
                    End If
                End If
            Next
        End If

        Return respuesta
    End Function

End Class
